package al.xc.liveapi.controller;

import al.xc.common.middleware.ContextHolder;
import al.xc.data.dto.SessionInfo;
import al.xc.data.dto.userinfo.getUserInfoRef;
import al.xc.data.dto.userinfo.getUserInfoReq;
import al.xc.datasource.mapper.AccountInfoMapper;
import al.xc.datasource.model.AccountInfo;
import al.xc.liveapi.controller.base.BaseController;
import al.xc.liveapi.data.ResultVo;
import al.xc.service.ITokenService;
import al.xc.service.IUserService;
import al.xc.service.impl.UserServiceImpl;
import al.xc.springboot.aop.ParamValidate;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

@Slf4j
@RestController
@Api("测试管理")
@RequestMapping("/test")
public class TestController extends BaseController {

    @Autowired
    private AccountInfoMapper mapper;
    @Autowired
    private IUserService userService;

    /**
     *
     * @param num
     * @param result
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "获取用户信息", notes = "通过数量获取用户信息")
    @ParamValidate(author = 1)
    @PostMapping("/test")
    public ResultVo<List<AccountInfo>> test(@RequestBody @Valid @ApiParam("数量") Integer num, BindingResult result) throws Exception {
        SessionInfo sessionInfo = ContextHolder.get(ContextHolder.USER_TOKEN);
        return successResult(mapper.selectList(new LambdaQueryWrapper<AccountInfo>().eq(AccountInfo::getId, sessionInfo.getId())));
    }

    @ApiOperation(value = "测试用户信息", notes = "通过测试数量获取用户信息")
    @ParamValidate(author = 1)
    @PostMapping("/testUserInfo")
    public ResultVo<List<getUserInfoRef>> testUserInfo(@RequestBody @Valid getUserInfoReq req, BindingResult result) throws Exception {
        return successResult(  userService.find(req.getToken()));
    }
}
